package com.atguigu.shiro.Web;

import com.atguigu.shiro.dao.SysUserMapper;
import com.atguigu.shiro.entity.SysUser;
import com.atguigu.shiro.response.WebResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.Valid;

@Slf4j
@RestController
public class MyController {
    @Resource
    private SysUserMapper sysUserMapper;

    // 跳转到测试页面
    @GetMapping("/testHtml")
    public ModelAndView testHtml() {
        return new ModelAndView("test");
    }

    @RequestMapping(value = "/a",method = RequestMethod.GET)
    public String a(){
        return "a";
    }

    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public WebResponse test(@Valid @RequestBody SysUser sysUser){
        return WebResponse.resSuccess("查询成功",sysUserMapper.select(sysUser));
    }

    /**
     * https://www.cnblogs.com/y369/p/10645425.html
     */
    //测试new ModelAndView(String viewName)构造方法
    @GetMapping("/modelAndView1")
    public ModelAndView modelAndView1() {
        //new ModelAndView("/modelAndView")和new ModelAndView("modelAndView")都可以
//      return new ModelAndView("/modelAndView");
        return new ModelAndView("modelAndView","name","张三");
        //重定向的地址注意，完全地址且前面需要加/
//      return new ModelAndView("redirect:/ModelAndView/modelAndView2");
    }
}
